package com.zhaoxi.project.cms.tag.service.impl;
import java.util.List;
import com.zhaoxi.common.utils.DateUtils;
import com.zhaoxi.project.cms.blog.mapper.CmsBlogTagMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhaoxi.project.cms.tag.mapper.CmsTagMapper;
import com.zhaoxi.project.cms.tag.domain.CmsTag;

/**
 * 标签信息Service业务层处理
 *
 * @author zhaoxi
 * @date 2023-07-28
 */
@Service
public class CmsTagServiceImpl
{
    @Autowired
    private CmsTagMapper cmsTagMapper;
    @Autowired
    private CmsBlogTagMapper cmsBlogTagMapper;

    /**
     * 查询标签信息
     *
     * @param tagId 标签信息主键
     * @return 标签信息
     */

    public CmsTag selectCmsTagByTagId(Long tagId)
    {
        return cmsTagMapper.selectCmsTagByTagId(tagId);
    }

    /**
     * 查询标签信息列表
     *
     * @param cmsTag 标签信息
     * @return 标签信息
     */

    public List<CmsTag> selectCmsTagList(CmsTag cmsTag)
    {
        List<CmsTag> cmsTagList = cmsTagMapper.selectCmsTagList(cmsTag);
        for (CmsTag tag : cmsTagList) {
            int blogNum = cmsBlogTagMapper.countBlogByTagId(tag.getTagId());
            tag.setBlogNum(blogNum);
        }
        return cmsTagList;
        //return cmsTagMapper.selectCmsTagList(cmsTag);
    }

    /**
     * 新增标签信息
     *
     * @param cmsTag 标签信息
     * @return 结果
     */

    public int insertCmsTag(CmsTag cmsTag)
    {
        cmsTag.setCreateTime(DateUtils.getNowDate());
        return cmsTagMapper.insertCmsTag(cmsTag);
    }

    /**
     * 修改标签信息
     *
     * @param cmsTag 标签信息
     * @return 结果
     */

    public int updateCmsTag(CmsTag cmsTag)
    {
        cmsTag.setUpdateTime(DateUtils.getNowDate());
        return cmsTagMapper.updateCmsTag(cmsTag);
    }

    /**
     * 批量删除标签信息
     *
     * @param tagIds 需要删除的标签信息主键
     * @return 结果
     */

    public int deleteCmsTagByTagIds(Long[] tagIds)
    {
        return cmsTagMapper.deleteCmsTagByTagIds(tagIds);
    }

    /**
     * 删除标签信息信息
     *
     * @param tagId 标签信息主键
     * @return 结果
     */

    public int deleteCmsTagByTagId(Long tagId)
    {
        return cmsTagMapper.deleteCmsTagByTagId(tagId);
    }
}

